import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';
import 'package:xvideos/tools_base/global_store/store.dart';

import '../widgets/tap_widget.dart';

class GoldToIntegralAlert extends StatelessWidget {
  final ValueNotifier selectGoldNof = ValueNotifier(0);
  // WalletModelEntity? wallet;
  ValueNotifier walletNof = ValueNotifier(0);
  GoldToIntegralAlert({super.key}) {
    globalStore.refreshWallet().then((value) {
      walletNof.value = (value?.amount ?? 0) + (value?.income ?? 0);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Material(
        color: Colors.transparent,
        child: Container(
          // color: Colors.transparent,

          margin: const EdgeInsets.symmetric(horizontal: 16),
          child: Stack(
            alignment: Alignment.topCenter,
            children: [
              Container(
                height: 394,
                width: double.infinity,
                margin: const EdgeInsets.only(bottom: 69),
                padding: const EdgeInsets.symmetric(horizontal: 24),
                decoration: BoxDecoration(
                    gradient: const LinearGradient(
                        colors: [Color(0xffffe8e8), Colors.white], begin: Alignment.topCenter, end: Alignment.bottomCenter),
                    borderRadius: BorderRadius.circular(18)),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    30.sizeBoxH,
                    const Text(
                      '钻石兑换积分',
                      style: TextStyle(color: Color(0xff333333), fontSize: 24, fontWeight: FontWeight.w500),
                    ),
                    18.sizeBoxH,
                    const Text(
                      '可用1钻石兑换10积分',
                      style: TextStyle(color: Color(0xff666666), fontSize: 14, fontWeight: FontWeight.w500),
                    ),
                    29.sizeBoxH,
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        SvgPicture.asset(
                          'assets/images/nut/big_gold.svg',
                          width: 54,
                          height: 54,
                        ),
                        34.sizeBoxW,
                        SvgPicture.asset(
                          'assets/images/nut/to_exchange.svg',
                          width: 44,
                          height: 44,
                        ),
                        34.sizeBoxW,
                        SvgPicture.asset(
                          'assets/images/nut/big_integral.svg',
                          width: 54,
                          height: 54,
                        )
                      ],
                    ),
                    29.sizeBoxH,
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        const Text(
                          '持有钻石',
                          style: TextStyle(color: Color(0xff666666), fontSize: 14, fontWeight: FontWeight.w500),
                        ),
                        ValueListenableBuilder(
                          valueListenable: walletNof,
                          builder: (_, value, __) => Text(
                            '$value',
                            style: const TextStyle(color: Color(0xff666666), fontSize: 14, fontWeight: FontWeight.w500),
                          ),
                        )
                      ],
                    ),
                    29.sizeBoxH,
                    Row(
                      children: [
                        const Text(
                          '兑换',
                          style: TextStyle(color: Color(0xff666666), fontSize: 14, fontWeight: FontWeight.w500),
                        ),
                        const Spacer(),
                        TapWidget(
                            SvgPicture.asset(
                              'assets/images/nut/gold_reduce.svg',
                              width: 28,
                              height: 28,
                            ), ontap: () {
                          if (selectGoldNof.value == 0) return;
                          selectGoldNof.value = selectGoldNof.value - 1;
                        }),
                        15.sizeBoxW,
                        ValueListenableBuilder(
                          valueListenable: selectGoldNof,
                          builder: (_, value, __) => Text(
                            '$value',
                            style: const TextStyle(color: Color(0xff333333), fontSize: 16, fontWeight: FontWeight.w500),
                          ),
                        ),
                        15.sizeBoxW,
                        TapWidget(
                            SvgPicture.asset(
                              'assets/images/nut/gold_add.svg',
                              width: 28,
                              height: 28,
                            ), ontap: () {
                          selectGoldNof.value = selectGoldNof.value + 1;
                        }),
                      ],
                    ),
                    24.sizeBoxH,
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        const Text(
                          '获得积分',
                          style: TextStyle(color: Color(0xff666666), fontSize: 14, fontWeight: FontWeight.w500),
                        ),
                        ValueListenableBuilder(
                          valueListenable: selectGoldNof,
                          builder: (_, value, __) => Text(
                            '${value * 10}',
                            style: const TextStyle(color: Color(0xff666666), fontSize: 14, fontWeight: FontWeight.w500),
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
              Positioned(
                bottom: 0,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    TapWidget(
                        Container(
                          height: 46,
                          width: 244,
                          alignment: Alignment.center,
                          decoration: BoxDecoration(color: Color(0xffF68216), borderRadius: BorderRadius.circular(22)),
                          child: const Text(
                            '消耗钻石',
                            style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.w500),
                          ),
                        ), ontap: () async {
                      if (selectGoldNof.value == 0) return;
                      // final res = await MineService.goldExchangeToIntegral(selectGoldNof.value);
                      // if (res) {
                      //   showToast( '兑换成功');
                      //   Get.back(result: selectGoldNof.value * 10);
                      // }
                    }),
                    TapWidget(
                        Container(
                          height: 46,
                          width: 244,
                          color: Colors.transparent,
                          alignment: Alignment.center,
                          child: const Text(
                            '我再看看',
                            style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.w500),
                          ),
                        ),
                        ontap: () => Get.back())
                  ],
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
